class Solution {
    public static void main(String[] args) {
        System.out.println(isMatch("a" , ".*..a*"));
    }
    public static boolean isMatch(String s, String p) {
        int n = s.length() ;
        int m = p.length() ;
        s = " "+ s ;
        p = " " + p ;
        boolean[][] dp = new boolean[n+1][m+1]  ;
        char[] sArr = s.toCharArray() ;
        char[] pArr = p.toCharArray() ;
        dp[0][0] = true ;
        for(int i=2 ; i <= m ; i +=2){
            if(pArr[i] == '*'){
                dp[0][i] = true ;
            }else{
                break ;
            }
        }
        for(int i=1 ; i <= n ; i ++){
            for(int j=1 ; j <=m ; j ++){
                if(pArr[j]>='a'&&pArr[j]<='z'){
                    dp[i][j] = sArr[i]==pArr[j] ? dp[i-1][j-1] : false ; ;
                }else{
                    if(pArr[j]=='.'){
                        dp[i][j] = dp[i-1][j-1];
                    }else{
                        dp[i][j] = pArr[j-1]=='.'? (dp[i][j-2]||dp[i-1][j]) : dp[i][j-2] || (sArr[i]==pArr[j-1] && dp[i-1][j] );
                    }
                }
            }
        }




        return dp[n][m] ;
    }
}